home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / DataOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.7 KB  |  180 lines

  1. package java.io;
  2.  
  3. public class DataOutputStream extends FilterOutputStream implements DataOutput {
  4.    protected int written;
  5.    private byte[] bytearr = null;
  6.    private byte[] writeBuffer = new byte[8];
  7.  
  8.    public DataOutputStream(OutputStream var1) {
  9.       super(var1);
  10.    }
  11.  
  12.    private void incCount(int var1) {
  13.       int var2 = this.written + var1;
  14.       if (var2 < 0) {
  15.          var2 = Integer.MAX_VALUE;
  16.       }
  17.  
  18.       this.written = var2;
  19.    }
  20.  
  21.    public synchronized void write(int var1) throws IOException {
  22.       this.out.write(var1);
  23.       this.incCount(1);
  24.    }
  25.  
  26.    public synchronized void write(byte[] var1, int var2, int var3) throws IOException {
  27.       this.out.write(var1, var2, var3);
  28.       this.incCount(var3);
  29.    }
  30.  
  31.    public void flush() throws IOException {
  32.       this.out.flush();
  33.    }
  34.  
  35.    public final void writeBoolean(boolean var1) throws IOException {
  36.       this.out.write(var1 ? 1 : 0);
  37.       this.incCount(1);
  38.    }
  39.  
  40.    public final void writeByte(int var1) throws IOException {
  41.       this.out.write(var1);
  42.       this.incCount(1);
  43.    }
  44.  
  45.    public final void writeShort(int var1) throws IOException {
  46.       this.out.write(var1 >>> 8 & 255);
  47.       this.out.write(var1 >>> 0 & 255);
  48.       this.incCount(2);
  49.    }
  50.  
  51.    public final void writeChar(int var1) throws IOException {
  52.       this.out.write(var1 >>> 8 & 255);
  53.       this.out.write(var1 >>> 0 & 255);
  54.       this.incCount(2);
  55.    }
  56.  
  57.    public final void writeInt(int var1) throws IOException {
  58.       this.out.write(var1 >>> 24 & 255);
  59.       this.out.write(var1 >>> 16 & 255);
  60.       this.out.write(var1 >>> 8 & 255);
  61.       this.out.write(var1 >>> 0 & 255);
  62.       this.incCount(4);
  63.    }
  64.  
  65.    public final void writeLong(long var1) throws IOException {
  66.       this.writeBuffer[0] = (byte)((int)(var1 >>> 56));
  67.       this.writeBuffer[1] = (byte)((int)(var1 >>> 48));
  68.       this.writeBuffer[2] = (byte)((int)(var1 >>> 40));
  69.       this.writeBuffer[3] = (byte)((int)(var1 >>> 32));
  70.       this.writeBuffer[4] = (byte)((int)(var1 >>> 24));
  71.       this.writeBuffer[5] = (byte)((int)(var1 >>> 16));
  72.       this.writeBuffer[6] = (byte)((int)(var1 >>> 8));
  73.       this.writeBuffer[7] = (byte)((int)(var1 >>> 0));
  74.       this.out.write(this.writeBuffer, 0, 8);
  75.       this.incCount(8);
  76.    }
  77.  
  78.    public final void writeFloat(float var1) throws IOException {
  79.       this.writeInt(Float.floatToIntBits(var1));
  80.    }
  81.  
  82.    public final void writeDouble(double var1) throws IOException {
  83.       this.writeLong(Double.doubleToLongBits(var1));
  84.    }
  85.  
  86.    public final void writeBytes(String var1) throws IOException {
  87.       int var2 = var1.length();
  88.  
  89.       for(int var3 = 0; var3 < var2; ++var3) {
  90.          this.out.write((byte)var1.charAt(var3));
  91.       }
  92.  
  93.       this.incCount(var2);
  94.    }
  95.  
  96.    public final void writeChars(String var1) throws IOException {
  97.       int var2 = var1.length();
  98.  
  99.       for(int var3 = 0; var3 < var2; ++var3) {
  100.          char var4 = var1.charAt(var3);
  101.          this.out.write(var4 >>> 8 & 255);
  102.          this.out.write(var4 >>> 0 & 255);
  103.       }
  104.  
  105.       this.incCount(var2 * 2);
  106.    }
  107.  
  108.    public final void writeUTF(String var1) throws IOException {
  109.       writeUTF(var1, this);
  110.    }
  111.  
  112.    static int writeUTF(String var0, DataOutput var1) throws IOException {
  113.       int var2 = var0.length();
  114.       int var3 = 0;
  115.       int var5 = 0;
  116.  
  117.       for(int var6 = 0; var6 < var2; ++var6) {
  118.          char var4 = var0.charAt(var6);
  119.          if (var4 >= 1 && var4 <= 127) {
  120.             ++var3;
  121.          } else if (var4 > 2047) {
  122.             var3 += 3;
  123.          } else {
  124.             var3 += 2;
  125.          }
  126.       }
  127.  
  128.       if (var3 > 65535) {
  129.          throw new UTFDataFormatException("encoded string too long: " + var3 + " bytes");
  130.       } else {
  131.          Object var15 = null;
  132.          byte[] var16;
  133.          if (var1 instanceof DataOutputStream) {
  134.             DataOutputStream var7 = (DataOutputStream)var1;
  135.             if (var7.bytearr == null || var7.bytearr.length < var3 + 2) {
  136.                var7.bytearr = new byte[var3 * 2 + 2];
  137.             }
  138.  
  139.             var16 = var7.bytearr;
  140.          } else {
  141.             var16 = new byte[var3 + 2];
  142.          }
  143.  
  144.          var16[var5++] = (byte)(var3 >>> 8 & 255);
  145.          var16[var5++] = (byte)(var3 >>> 0 & 255);
  146.          int var17 = 0;
  147.  
  148.          for(var17 = 0; var17 < var2; ++var17) {
  149.             char var8 = var0.charAt(var17);
  150.             if (var8 < 1 || var8 > 127) {
  151.                break;
  152.             }
  153.  
  154.             var16[var5++] = (byte)var8;
  155.          }
  156.  
  157.          for(; var17 < var2; ++var17) {
  158.             char var9 = var0.charAt(var17);
  159.             if (var9 >= 1 && var9 <= 127) {
  160.                var16[var5++] = (byte)var9;
  161.             } else if (var9 > 2047) {
  162.                var16[var5++] = (byte)(224 | var9 >> 12 & 15);
  163.                var16[var5++] = (byte)(128 | var9 >> 6 & 63);
  164.                var16[var5++] = (byte)(128 | var9 >> 0 & 63);
  165.             } else {
  166.                var16[var5++] = (byte)(192 | var9 >> 6 & 31);
  167.                var16[var5++] = (byte)(128 | var9 >> 0 & 63);
  168.             }
  169.          }
  170.  
  171.          var1.write(var16, 0, var3 + 2);
  172.          return var3 + 2;
  173.       }
  174.    }
  175.  
  176.    public final int size() {
  177.       return this.written;
  178.    }
  179. }
  180.